import { ApiTrack } from '../core';
import { ApiTrackPlugin, EventName } from '../types';
import { formatReportInfo } from '@/utils/format-report-info';

export const collector: ApiTrackPlugin<ApiTrack, unknown> = (apiTrack) => {
  return (resultInfos) => {
    if (!resultInfos) return;
    const categories = formatReportInfo(resultInfos);
    // 发送自定义日志
    apiTrack.reporter.sendLog(resultInfos?.type === 'success' ? EventName.ValidateSuccess : EventName.ValidateFail, {
      categories,
    });
  };
};
